<!doctype html>
<html>
<head>

	<title>Custom types</title>
	<link rel="stylesheet" type="text/css" href="../../../codebase/webix.css">
	<script type="text/javascript" src="../../../codebase/webix.js"></script>

</head>
<body>
<script>

	/*
	*   Code39 definition
	* */
	webix.type(webix.ui.barcode, {
		name:"code39",

		// chars encodings
		encodings:[
			"110101001011", "101101001011", "110110100101", "101011001011",
			"110101100101", "101101100101", "101010011011", "110101001101",
			"101101001101", "101011001101", "110101010011", "101101010011",
			"110110101001", "101011010011", "110101101001", "101101101001",
			"101010110011", "110101011001", "101101011001", "101011011001",
			"110010101011", "100110101011", "110011010101", "100101101011",
			"110010110101", "100110110101", "101001101101", "110100101011",
			"101100101011", "110110010101", "101001101011", "110100110101",
			"101100110101", "101001011011", "110100101101", "101100101101",
			"100101011011", "110010101101", "100110101101", "100100100101",
			"100100101001", "100101001001", "101001001001", "100101101101"
		],

		// encodes chars
		encode: function(value){
			var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-. $/+%*",
				code="",
				i, pos,
				sepChar='0';

			if (value.indexOf("*")!=-1)
				return "";

			value = this.template(value);

			for(i=0; i<value.length; i++){
				pos = chars.indexOf( value.charAt(i) );
				if (pos < 0)
					return "";
				if (i > 0)
					code += sepChar;
				code += this.encodings[pos];
			}
			return code;
		},

		// text
		template: function(value){
			return ("*" + value + "*").toUpperCase();
		}
	});

	webix.ready(function(){
		webix.ui({
			view: "window",
			head: "Custom barcode type",
			width: 420,
			left:100,
			top: 100,
			body:{
				type: "clean",
				cols:[
					{},
					{	view: "barcode",
						type: "code39",
						width: 250,
						value: "CODE 39"
					},
					{}
				]


			}
		}).show();
	});


</script>
</body>
</html>